#!/usr/bin/env python
# coding: utf-8

import tornado.web
import tornado.httpserver
import tornado.ioloop
from tornado.web import RequestHandler, url
'''
请求对象的属性
'''

class IndexHandler(RequestHandler):
    def get(self, *args, **kwargs):
        '''
        http://me.localhost.cn:8000/user/groups?pretty=true
        method: GET
        host: me.localhost.cn:8000
        uri: /user/groups?pretty=true
        path: /user/groups
        query: pretty=true
        version: HTTP/1.1
        headers: "
            Host: me.localhost.cn:8000
            Connection: keep-alive
            Cache-Control: max-age=0
            Upgrade-Insecure-Requests: 1
            User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36
            Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
            Accept-Encoding: gzip, deflate
            Accept-Language: zh-CN,zh;q=0.8,en;q=0.6
        "
        '''
        request = self.request
        print("method",request.method)
        print("host",request.host)
        print("uri",request.uri)
        print("path",request.path)
        print("query",request.query)
        print("version",request.version)
        print("headers",request.headers)
        print("body",request.body)
        print("remote_ip",request.remote_ip)
        self.write("ok")

    def post(self, *args, **kwargs):
        self.get(*args,**kwargs)

if __name__ == '__main__':
    app = tornado.web.Application([
        url(r'/.*$', IndexHandler),
    ])
    http_server = tornado.httpserver.HTTPServer(app)
    http_server.bind(8000)
    http_server.start(1)
    tornado.ioloop.IOLoop.current().start()